import ogre.renderer.OGRE as ogre

from EventController import *

class CinematicController:
    def __init__(self, camera, cameraNode, eventController):
        self.camera = camera
        self.cameraNode = cameraNode
        self.cameraPos = ogre.Vector3(0.0, 1.0, 8.0) #was 0.0, 2.15, 11.0
        self.camera.setPosition(self.cameraPos) #7 units back from camera node. Camera node is where the henchmen layer is located.
              
        self.advanceUnit = ogre.Vector3(0.0, 0.0, -1.0)
        self.advanceLeftRight = ogre.Vector3(1.0, 0.0, 0.0)
        
        eventController.subscribe(Events.PLAYERMOVE, self.onPlayerMove, "ALL")
        
    def onPlayerMove(self, positionOrient):
        position = positionOrient[0]
        orient = positionOrient[1]
        #currentPos = self.cameraNode.getPosition()
        #newPos = ogre.Vector3(currentPos.x, currentPos.y, position.z) #we do this because the game only moves on the z layers.
        #self.cameraNode.setOrientation(orient)
        self.camera.setOrientation(orient)
        self.cameraNode.setPosition(position)
        return  
    def update(self, dt):
        return True
    
    def advance(self):
        self.cameraNode.translate(self.advanceUnit)
        
    def retreat(self):
        self.cameraNode.translate(self.advanceUnit * -1)
        
    def left(self):
        self.cameraNode.translate(self.advanceLeftRight * -1)
    def right(self):
        self.cameraNode.translate(self.advanceLeftRight)
        
        
    